<template>
  <div id="tab-bar">
    <div
      class="tab-bar-item"
      v-for="(item,index) in tabbarItem"
      :key="index"
      @click="itemCLick(index)"
    >
      <span class="tabtxt" :class="{active:currentIndex==index}">{{item}}</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    tabbarItem: {
      type: Array,
    },
  },
  data() {
    return {
      currentIndex: 0,
    };
  },
  methods: {
    itemCLick(index) {
      this.currentIndex = index;
      this.$emit("tabbarItemClick", index);
    },
  },
};
</script>

<style scoped>
#tab-bar {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #eee;
  background-color: #ffffff;
  text-align: center;
}
.tab-bar-item {
  flex: 1;
  color: #333;
  font-size: 15px;
  font-weight: 400;
  height: 40px;
  line-height: 40px;
}
.tabtxt {
  position: relative;
}
.active {
  color: #dd001b;
}
.active::after {
  content: "";
  position: absolute;
  left: -10%;
  bottom: -13px;
  z-index: 3;
  width: calc(100% + 20%);
  height: 2px;
  background: #dd001b;
}
</style>